package com.juneng.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.juneng.constant.Constant;
import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayInputStream;

/**
 * @ClassName AliOSSUtil.java
 * @Description 功能描述： 阿里云OSS文件上传
 * @author 吴昊 2018年3月6日20:01:21
 */
@Slf4j
public class AliOSSUtil {



    public static String myUpload(byte[] bytes, String fileName, String endPoint, String accessKeyId, String accessKeySecret) {
        String objectName = Constant.OSS_UPLOAD_PATH + fileName;
        OSS ossClient = new OSSClientBuilder().build(endPoint,accessKeyId,accessKeySecret);
        ossClient.putObject(Constant.BUCKET_NAME, objectName, new ByteArrayInputStream(bytes));
        ossClient.shutdown();
        return Constant.FILE_HOST + objectName;
    }

}
